package com.example.mall.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.Assert;

import java.util.Arrays;

@AllArgsConstructor
@Getter
public enum DriveLetterEnum {

    C("C:", "C盘"),
    D("D:", "D盘"),
    E("E:", "E盘"),
    F("F:", "F盘"),
    EMPTY("", "EMPTY"),
    ;

    /** 盘符编码 */
    private final String code;

    /** 盘符名称 */
    private final String name;

    public static String getStartsWithDriveLetterIfExists(String path) {
        Assert.notNull(path, "path不能为空");
        DriveLetterEnum driveLetterEnum = Arrays.stream(values()).filter(f -> path.contains(f.code)).findAny().orElse(EMPTY);
        return driveLetterEnum.equals(EMPTY) ? path : path.substring(path.indexOf(driveLetterEnum.code));
    }

}
